<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>30 购物车</title>
    <script src="./js/vue.js"></script>
    <style>
        .table {
            width: 1000px;
            margin: 50px auto;
        }

        .table .tr {
            width: 1000px;
        }

        .table .tr .item {
            width: 150px;
            height: 50px;
            line-height: 50px;
            background-color: blue;
            color: coral;
            text-align: center;
            float: left;
        }
        .table .tr .item input{
            width: 50px;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="table">
            <div class="tr">
                <div class="item">
                    全选
                    <input type="checkbox">
                </div>
                <div class="item">
                    商品名称
                </div>
                <div class="item">
                    商品价格
                </div>
                <div class="item">
                    商品数量
                </div>
                <div class="item">
                    小计
                </div>
                <div class="item">
                    操作
                </div>
            </div>
            <div class="tr" v-for="item in list">
                <div class="item">
                    <input type="checkbox" :checked="item.ischecked">
                </div>
                <div class="item">
                    {{item.goodsname}}
                </div>
                <div class="item">
                    {{item.goodsprice.toFixed(2)}}
                </div>
                <div class="item">
                    <button v-show="item.goodsnum > 1" @click="cale(item,-1)">-</button>
                    <input type="number" :value="item.goodsnum">
                    <button @click="cale(item,1)">+</button>
                </div>
                <div class="item">
                    {{(item.goodsnum * item.goodsprice).toFixed(2)}}
                </div>
                <div class="item" @click="del(item.id)">
                    删除
                </div>
            </div>
        </div>
    </div>   
</body>
<script>
    new Vue({
        el: "#app",
        data: {
            list: [
                { id: 1, goodsname: "商品一", goodsnum: 10, goodsprice: 100, ischecked: false },
                { id: 2, goodsname: "商品二", goodsnum: 10, goodsprice: 100, ischecked: true },
                { id: 3, goodsname: "商品三", goodsnum: 10, goodsprice: 100, ischecked: false },
            ],
        },
        methods: {
            cale(item,num){
                item.goodsnum = item.goodsnum+num;
            },
            del(id){
                this.list = this.list.filter(item => item.id != id);
            }

        },
        watch: {

        }
    })
</script>

</html>